#ifndef THREAD_SEARCH_H
#define THREAD_SEARCH_H

#include <wx/string.h>
#include <wx/splitter.h>
#include <M_Code_plugin.h>
#include <globals.h>
#include "ThreadSearchFindData.h"
#include "ThreadSearchViewManagerBase.h"
#include "ThreadSearchLoggerBase.h"
#include "InsertIndexManager.h"

class wxWindow;
class wxMenu;
class wxMenuBar;
class wxToolBar;
class wxLogWindow;
class wxComboBox;
class FileTreeData;
class wxCommandEvent;
class wxUpdateUIEvent;
class cbConfigurationPanel;
class M_Code_Project;
class ThreadSearchView;

class ThreadSearch : public M_Code_Plugin {
  public:
    ThreadSearch();
    virtual ~ThreadSearch();
    virtual int GetConfigurationPriority() const { return 50; }
    virtual int GetConfigurationGroup() const { return cgContribPlugin; }
    virtual cbConfigurationPanel* GetConfigurationPanel( wxWindow* parent );
    virtual cbConfigurationPanel* GetProjectConfigurationPanel( wxWindow* ( parent ), M_Code_Project* ( project ) ) { return 0; }
    virtual void BuildMenu( wxMenuBar* menuBar );
    virtual void BuildModuleMenu( const ModuleType type, wxMenu* pMenu, const FileTreeData* data = 0 );
    void Notify();
    void SetCtxMenuIntegration( bool ctxMenuIntegration ) {m_CtxMenuIntegration = ctxMenuIntegration;}
    void SetUseDefValsForThreadSearch( bool useDefVals ) {m_UseDefValsForThreadSearch = useDefVals;}
    void SetShowSearchControls( bool showSearchControls ) {m_ShowSearchControls = showSearchControls;}
    void SetShowDirControls( bool showDirControls ) {m_ShowDirControls = showDirControls;}
    void SetShowCodePreview( bool showCodePreview ) {m_ShowCodePreview = showCodePreview;}
    void SetDeletePreviousResults( bool deletePreviousResults ) {m_DeletePreviousResults = deletePreviousResults;}
    void SetDisplayLogHeaders( bool displayLogHeaders ) {m_DisplayLogHeaders = displayLogHeaders;}
    void SetDrawLogLines( bool drawLogLines ) {m_DrawLogLines = drawLogLines;}
    void SetAutosizeLogColumns( bool autosizeLogColumns ) {m_AutosizeLogColumns = autosizeLogColumns;}
    void SetFindData( const ThreadSearchFindData& findData ) {m_FindData = findData;}
    void SetManagerType( ThreadSearchViewManagerBase::eManagerTypes mgrType );
    void SetLoggerType( ThreadSearchLoggerBase::eLoggerTypes lgrType ) {m_LoggerType   = lgrType;}
    void SetSplitterMode( wxSplitMode splitterMode ) {m_SplitterMode = splitterMode;}
    void SetFileSorting( InsertIndexManager::eFileSorting fileSorting ) {m_FileSorting  = fileSorting;}
    bool GetCtxMenuIntegration() const {return m_CtxMenuIntegration;}
    bool GetUseDefValsForThreadSearch() const {return m_UseDefValsForThreadSearch;}
    bool GetShowSearchControls() const {return m_ShowSearchControls;}
    bool GetShowDirControls() const {return m_ShowDirControls;}
    bool GetShowCodePreview() const {return m_ShowCodePreview;}
    bool GetDeletePreviousResults() const {return m_DeletePreviousResults;}
    bool GetDisplayLogHeaders() const {return m_DisplayLogHeaders;}
    bool GetDrawLogLines() const {return m_DrawLogLines;}
    bool GetAutosizeLogColumns() const {return m_AutosizeLogColumns;}
    void GetFindData( ThreadSearchFindData& findData ) const {findData = m_FindData;}
    ThreadSearchFindData& GetFindData() {return m_FindData;}
    ThreadSearchViewManagerBase::eManagerTypes GetManagerType() const {return m_pViewManager->GetManagerType();}
    ThreadSearchLoggerBase::eLoggerTypes GetLoggerType()  const {return m_LoggerType;}
    long GetSplitterMode() const {return m_SplitterMode;}
    InsertIndexManager::eFileSorting GetFileSorting()  const {return m_FileSorting;}
    void RunThreadSearch( const wxString& text, bool isCtxSearch = false );
    void OnThreadSearchViewDestruction();
    wxLogWindow* m_pLog;
  protected:
    virtual void OnAttach();
    virtual void OnRelease( bool appShutDown );
    virtual void LoadConfig( bool &showPanel, int &sashPosition,
                             ThreadSearchViewManagerBase::eManagerTypes& mgrType,
                             wxArrayString& searchPatterns, wxArrayString& searchDirs,
                             wxArrayString& searchMasks );
    virtual void SaveConfig( bool showPanel, int sashPosition,
                             ThreadSearchViewManagerBase::eManagerTypes mgrType,
                             const wxArrayString& searchPatterns, const wxArrayString& searchDirs,
                             const wxArrayString& searchMasks );
  private:
    void OnMnuViewThreadSearch( wxCommandEvent& event );
    void OnMnuSearchThreadSearch( wxCommandEvent& event );
    void OnMnuViewFocusThreadSearch( wxCommandEvent& event );
    void OnCtxThreadSearch( wxCommandEvent& event );
    void OnMnuViewThreadSearchUpdateUI( wxUpdateUIEvent& event );
    void OnMnuSearchThreadSearchUpdateUI( wxUpdateUIEvent& event );
    void OnMnuViewFocusThreadSearchUpdateUI( wxUpdateUIEvent& event );
    void OnBtnOptionsClick( wxCommandEvent& event );
    void OnBtnSearchClick( wxCommandEvent& event );
    void OnCboSearchExprEnter( wxCommandEvent &event );
    static bool GetCursorWord( wxString& sWord );
    int GetInsertionMenuIndex( const wxMenu* const pCtxMenu );
    void OnMnuEditCopy( wxCommandEvent& event );
    void OnMnuEditCopyUpdateUI( wxUpdateUIEvent& event );
    void OnMnuEditPaste( wxCommandEvent& event );
    wxString m_SearchedWord;
    ThreadSearchFindData m_FindData;
    ThreadSearchView* m_pThreadSearchView;
    ThreadSearchViewManagerBase* m_pViewManager;
    bool m_CtxMenuIntegration;
    bool m_UseDefValsForThreadSearch;
    bool m_ShowSearchControls;
    bool m_ShowDirControls;
    bool m_ShowCodePreview;
    bool m_DeletePreviousResults;
    ThreadSearchLoggerBase::eLoggerTypes m_LoggerType;
    bool m_DisplayLogHeaders;
    bool m_DrawLogLines;

    bool m_AutosizeLogColumns;
    bool m_OnReleased;
    wxComboBox* m_pCboSearchExpr;
    wxSplitMode m_SplitterMode;
    InsertIndexManager::eFileSorting m_FileSorting;
    DECLARE_EVENT_TABLE();
};

#endif
